<?php
/**
 * Created by JetBrains PhpStorm.
 * User: James
 * Date: 12-6-6
 * Time: 下午10:42
 * To change this template use File | Settings | File Templates.
 */

class Mark_model extends CI_Model {
    public function __construct(){
        $this->load->database();
    }

    public function get_marks(){
        $this->load->helper('url');

        $id = $this->input->post('id');
        if(!$id)
        {
            $query=$this->db->get("marks");
        }else
        {
            $query=$this->db->query("SELECT * FROM marks WHERE marks.id = ".$id." LIMIT 1");
        }

        return $query->result_array();
    }
    public function insert_marks()
    {
        $this->load->helper('url');

        $data = array(
            'title' => $this->input->post('title'),
            'address' => $this->input->post('address')
        );

        return $this->db->insert('marks', $data);
    }

    public function del_marks()
    {
        $this->load->helper('url');

        $id = $this->input->post('id');

        return $this->db->query("DELETE FROM marks WHERE marks.id = ".$id." LIMIT 1");
    }

    public function update_marks()
    {
        $this->load->helper('url');


            $id = $this->input->post('id');
           $title= $this->input->post('title');
            $address = $this->input->post('address')   ;


       $r= $this->db->query("UPDATE  marks SET  marks.title =  ".$title.", marks.address =  ".$address.", marks.date= NOW( ) WHERE  marks.id =".$id." LIMIT 1 ;");
        if($r)
        {
            $query=$this->db->query("SELECT * FROM marks WHERE marks.id = ".$id." LIMIT 1");
            return   $query->result_array();
        }else
        {
            return 0;
        }
    }
}